#include "mvcd.h"
#include "main.h"

MVCD::MVCD(QDialog *parent) :
    QDialog(parent), ui(new Ui::mvcd)
{
     ui->setupUi(this);
     setWindowFlags(Qt::FramelessWindowHint|Qt::SubWindow);
     QFile file(trUtf8( REMARK_FILE ));
     if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
     ui->textBrowser->setText(trUtf8(file.readAll()));
     ui->tableView->setItemDelegate(&delegate);

}


MVCD::~MVCD()
{

    delete ui;

}

void MVCD::savedata()
{
    mvcm.save(*mvcd_datamap);
    config_changed=true;
}

void MVCD::init( QMap<QString,int > init_datamap)
{
     mvcd_datamap=&init_datamap;
     mvcm.init(init_datamap);
    ui->tableView->setModel(&mvcm);
    initialized=true;
}

void MVCD::set_datamap( QMap<QString,int >* datamap,uint checktype)
{
    mvcd_datamap=datamap;
    mvcm.init(*datamap);
    ui->tableView->setModel(&mvcm);
    delegate.set_datamap(datamap,checktype);
    ui->tableView->setItemDelegate(&delegate);
    this->checktype=checktype;

}

void MVCD::on_pushButton_clicked()
{

    BUTTON_SOUND;
    if( Affirm("确认是否恢复出厂设置？") )
 {
        sterilization_default_setting_recovery(*mvcd_datamap,checktype);
        mvcm.init(*mvcd_datamap);//重置模型数据

 }
}


void MVCD::on_buttonBox_accepted()
{
     savedata();
    if(mvcd_datamap== &IO_setting_datamap) {read_IO_setting_data(IO_setting_datamap);}
    else if(mvcd_datamap== &sensor_adjust_datamap)
         {
            if(sterilizing)   save_config(DATA_FILE);sensor_data_changed=true;
         }
    else stype->sterilization_parameters_edited();
}

void MVCD::read_IO_setting_data(QMap<QString,int>& datamap)
{
    water_valve_pin=                        datamap[trUtf8("加水")];
    heating_valve_pin=                      datamap[trUtf8("加热")];
    air_intake_valve_pin=                   datamap[trUtf8("进气")];
    exhaust_valve_pin=                      datamap[trUtf8("排气")];
    Vacuum_pump_pin=                        datamap[trUtf8("真空泵")];
    air_supply_valve_pin=                   datamap[trUtf8("回气")];
    open_front_door_pin=                    datamap[trUtf8("开前门")];
    close_front_door_pin=                   datamap[trUtf8("关前门")];
    front_door_Sealing_strip_Inflation_pin= datamap[trUtf8("前密封")];
    front_door_Sealing_strip_Exhaust_pin=   datamap[trUtf8("前解封")];
    open_back_door_pin=                     datamap[trUtf8("开后门")];
    close_back_door_pin=                    datamap[trUtf8("关后门")];
    back_door_Sealing_strip_Inflation_pin=  datamap[trUtf8("后密封")];
    back_door_Sealing_strip_Exhaust_pin=    datamap[trUtf8("后解封")];

}

